<?php
$url = new Url(); 
?>
<script type="text/javascript">
    function ajaxQuickUpdate(id){
        var status = 0;var isHot = 0;var isHome = 0;
        if($("#status_"+id).is(":checked")){ status = 1; }
        var strUrl = "<?=$url->createUrl("tuviCategory/ajaxQuickUpdate") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                status:status,
                position:$("#position_"+id).val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?=$url->createUrl("tuviCategory/ajaxDelete") ?>";
        if(confirm(' Bạn có chắc chắn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="Tabs clearfix">
        <ul class="clearfix">
            <li><a href="<?php echo Url::createUrl("tuvi/index")?>"><span>Tử vi</span></a></li>
            <li><a href="#" class="active"><span>Danh mục</span></a></li>
        </ul>                
    </div>
    <div class="box">
        <div class="fillter clearfix">           
            <div class="fl">
            <a href="<?php echo Url::createUrl("tuviCategory/create")?>">
                <input type="button" value=" Thêm mới " class="btn-bigblue fl" style="margin-top:-3px"> 
            </a>
            </div>
        </div>
        <div class="table middle clearfix">
            <div class="table clearfix">
                <table width="100%" cellspacing="0" cellpadding="0" border="0">
                    <tbody>
                        <tr class="bg-grey">
                            <td width="4%"><strong>Mã </strong></td>
                            <td width="24%"><strong>Ảnh </strong></td>
                            <td width="30%"><strong>Tiêu đề</strong></td>
                            <td width="12%"><strong>Trạng thái</strong></td>
                            <td width="11%"><strong>Thứ tự</strong></td>
                            <td width="10%"><strong>Quản trị</strong></td>
                        </tr>
                        <?php
                        foreach($data as $key=>$value){
                            $link_img = Common::getImage($value["picture"],"tuvi",$value["create_date"]);
                        ?>
                        <tr>
                            <td><strong><?php echo $value["id"]?></strong></td>
                            <td><img src="<?php echo $link_img?>" width="85" height="85"></td>
                            <td class="text-left"><strong class="cl666"><?php echo $value["title"]?></strong></td>
                            <td><input type="checkbox" value="1" id="status_<?php echo $value["id"]?>" <?php echo $value["status"]==1 ? 'checked="checked"':'';?>> Hiển thị</td>
                            <td><input type="text" id="position_<?php echo $value["id"]?>" value="<?php echo $value["position"]?>"/></td>
                            <td>
                            <a class="s14" href="javascript:void(0)" onclick="ajaxQuickUpdate('<?php echo $value["id"]?>')"> Lưu </a> | 
                            <a href="<?php echo $url->createUrl("tuviCategory/edit",array("id"=>$value["id"]))?>"> Sửa </a> | 
                            <a href="javascript:void(0)" onclick="ajaxDelete('<?php echo $value["id"]?>')">  Xóa  </a> |
                            
                            </td>
                        </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>